﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WMS.HelperClasses;
using WHMS.HelperClasses;
using Microsoft.Reporting.WinForms;

namespace WMS.Reports
{	
	public partial class RemoveReportForm : Form
	{
		public RemoveReportForm()
		{
			InitializeComponent();
		}

		private void ItemBalanceForm_Load(object sender, EventArgs e)
		{
			FormsHelper.LoadComboBox(StoresDDL, StoreFields.Id, StoreFields.Name, (x, y) => DALHelper.GetDynamicList(x, y, null));
			//this.reportViewer1.RefreshReport();
			new FormsHelper().DisableReportExportToWord(this.reportViewer1);
		}

		private void RunBtn_Click(object sender, EventArgs e)
		{
			bindingSource1.DataSource = Business.GetWithdrawalReport(GetSelectedStoreId(), FromDateDTP.Value, ToDateDTP.Value);

			this.reportViewer1.LocalReport.DataSources.Clear();
			this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", bindingSource1));
            this.reportViewer1.LocalReport.SetParameters(new ReportParameter("StoreCode", GetSelectedStoreCode()));
			this.reportViewer1.LocalReport.SetParameters(new ReportParameter("StoreName", GetSelectedStoreName()));
			this.reportViewer1.LocalReport.SetParameters(new ReportParameter("FromDate", FromDateDTP.Value.ToShortDateString()));
			this.reportViewer1.LocalReport.SetParameters(new ReportParameter("ToDate", ToDateDTP.Value.ToShortDateString()));

			this.reportViewer1.RefreshReport();   

		}

		private int GetSelectedStoreId()
		{
			return (int)((System.Data.DataRowView)(StoresDDL.SelectedItem)).Row.ItemArray[0];
		}

		private string GetSelectedStoreName()
		{
			return (string)((System.Data.DataRowView)(StoresDDL.SelectedItem)).Row.ItemArray[1];
		}

        /// <summary>
        /// Retrieve selected store code 
        /// </summary>
        /// <returns>store code</returns>
        private string GetSelectedStoreCode()
        {
            DataTable dt = Business.GetStoreDetails(GetSelectedStoreId());
            return dt.Rows[0][1].ToString();
        }
	}
}
